﻿using System;
using System.Collections.Generic;
using System.Text;
using AspNetCs.IDAL;
using AspNetCs.DALFactory;
using AspNetCs.Model;
using System.Data;
using AspNetCs.Common;
namespace AspNetCs.Bll
{
    public class City
    {
        private ICity city = Conn.CreateCity();


        #region ICity 成员

        public City_Model GetModel(DataRow dr)
        {
            return city.GetModel(dr);
        }

        public int Add(City_Model model)
        {
            if (model == null)
            {
                return -1;
            }
            return city.Add(model);
        }

        public int update(City_Model model)
        {
            if (model == null)
            {
                return -1;
            }
            return city.update(model);
        }

        public int delete(int id)
        {
            if (id <= 0) return -1;
            return city.delete(id);
        }
        public DataTable CityList(int parentid)
        {
            return city.CityList(parentid);
        }
        public void UpdateOrder(int id)
        {
            city.UpdateOrder(id);
        }
        #endregion


        /// <summary>
        /// 通过编号获得省的名称
        /// </summary>
        /// <param name="provinceId"></param>
        /// <returns></returns>
        public string ProvinceName(int provinceId, int cityId)
        {
            City_Model cityModel = new City_Model();
            DataTable dataTable = city.CityList(provinceId);
            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                DataRow dataRow = dataTable.Rows[i];
                if (StringHelper.isNumber_int(dataRow["id"].ToString()) == cityId)
                {
                    cityModel = city.GetModel(dataRow);
                }
            }
            return cityModel.ProvinceName;
        }

        /// <summary>
        /// 通过编号获得城市的名称
        /// </summary>
        /// <param name="cityId"></param>
        /// <returns></returns>
        public string CityName(int provinceId,int cityId)
        {
            City_Model cityModel = new City_Model();
            DataTable dataTable=city.CityList(provinceId);
            for (int i = 0; i < dataTable.Rows.Count;i++ )
            {
                DataRow dataRow=dataTable.Rows[i];
                if (StringHelper.isNumber_int(dataRow["id"].ToString()) == cityId)
                {
                    cityModel = city.GetModel(dataRow);
                }
            }
            return cityModel.ClassName;
        }
    }
}
